package com.example.arithmeticleetcode.leetcode.September;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-09-18 11:40
 **/
public class Demo15 {

    public static void main(String[] args) {
        int[] A1 = {2,1};
        System.out.println(validMountainArray(A1));

        int[] A2 = {3,5,5};
        System.out.println(validMountainArray(A2));

        int[] A3 = {0,3,2,1};
        System.out.println(validMountainArray(A3));

        int[] A4 = {3,5,1};
        System.out.println(validMountainArray(A4));


    }

    public static boolean validMountainArray(int[] A) {
        if (A.length < 3) {
            return false;
        }
        int firstIndex = 0;
        int lastIndex = A.length - 1;
        while (firstIndex < A.length - 2 && A[firstIndex] < A[firstIndex + 1]) firstIndex++;
        while (lastIndex > 0 && A[lastIndex] < A[lastIndex - 1]) lastIndex --;
        return firstIndex == lastIndex;
    }
}
